/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.market.web.controller;

import com.market.web.EJB.CustomerFacade;
import com.market.web.model.Customer;
import java.io.IOException;
import java.io.PrintWriter;
import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Niroj Nalini
 */
@WebServlet("/registration")
public class CustomerController extends HttpServlet{

    @EJB
    private CustomerFacade customerFacade;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    //String id = req.getParameter("id");
        HttpSession session = req.getSession();
        
        
        String name = req.getParameter("name");
        String address = req.getParameter("address");
        String email = req.getParameter("email");
        String password = req.getParameter("password");
        String tel = req.getParameter("tel");
        
        Customer c =  new Customer();
        c.setName(name);
        c.setAddress(address);
        c.setTel(tel);
        c.setEmail(email);
        c.setPassword(password);
        
        customerFacade.create(c);
        session.setAttribute("cust", c);
        
        System.out.println("Success");
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        out.println("success");
        
        RequestDispatcher rd = req.getRequestDispatcher("login2.html");
        rd.forward(req,resp);
        return;
    }
    
    
    
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        
    }
    
    
            
}
